package com.itheima.service.Impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.JobData;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentData;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpJobData() {
        //查询到职位人数
        List<JobData> jobDataList = empMapper.empJobData();
        //解析并封装到JobOption里
        JobOption jobOption = new JobOption();
        // 把数据库查询到数据对象转成字符串集合，存放的职位名称
        List<String> jobList = jobDataList.stream().map(JobData::getJob).toList();
        jobOption.setJobList(jobList);//["教研主管","学工主管","其他","班主任","咨询师","讲师"],List<String>
        // 把数据库查询到数据对象转成数字集合，存放的职位人数
        List<Integer> countList = jobDataList.stream().map(JobData::getCount).toList();
        jobOption.setDataList(countList);//[1,1,2,6,8,13]
        return jobOption;
    }

    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }


    @Override
    public StudentOption getstudentCountData() {

        List<StudentData> studentOptionList = studentMapper.selectStudentCountData();

        StudentOption studentOption = new StudentOption();

        List<String> clazzNameList = studentOptionList.stream().map(StudentData::getClazzName).toList();
        studentOption.setClazzList(clazzNameList);
        List<Integer> countList = studentOptionList.stream().map(StudentData::getCount).toList();
        studentOption.setDataList(countList);
        return studentOption;

    }

    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }
}
